// ServerSocket.h

// Komunikacny modul komunikujuci so soccer serverom prostrednictvom UDP

#ifndef SERVERSOCKET_H
#define SERVERSOCKET_H

#include "Common/Interfaces/Communication.h"
#include "Common/Interfaces/MsgProcess.h"
#include "Common/Module.h"
#include "Common/Main.h"

#ifdef WIN32
#	include <winsock.h>
#else
#	include <netinet/in.h>
#endif

// Velkost buffera spravy
#define BUFFERSIZE 8192

// Modul komunikujuci so soccer serverom prostrednictvom UDP
class ServerSocket : public Module, public CommunicationInterface
{
	char message[BUFFERSIZE];			// Buffer pre prichadzajuce spravy

	MsgProcessInterface* parser;
//  MsgProcessInterface* clangparser;
	bool connected;
	int sock;							// Socket pre komunikaciu
	struct sockaddr_in address;			// Adresa servera

public:
	// Konstruktor
	ServerSocket();
	// Destruktor
	virtual ~ServerSocket();

	// Metody
	
	//
	virtual int Connect(const char* msg = NULL);
	//
	virtual int Disconnect(const char* msg = NULL);
	//
	virtual int Init(int argc, char** argv, int nTask = -1);
	//
	virtual int ReceiveMsg();
	//
	virtual void Run(int nTask = -1);
	//
	virtual int SendMsg(const char* msg);
	//
	virtual int SetServer(const char* addr, unsigned port);

	//
	virtual Interface* GetInterface(int nTask = -1) const;

};

#endif // SERVERSOCKET_H
